﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;



namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            Program obj = new Program();
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Green;
            if (File.Exists("colorcache.txt"))
            {
                int fil = int.Parse(File.ReadAllText("colorcache.txt"));
                

                obj.ccolor(fil);

            }
                  
            Console.Write("Shark-Prompt>>");
            string prompt = Console.ReadLine();
            if (prompt == "shutdown" )
            {
                obj.shutdown();
            }
            else if (prompt == "restart")
            {
                obj.restart();
            }
            else if (prompt == "t2s")
            {
                System.Diagnostics.Process.Start("T2S.vbs");
            }
            else if (prompt == "ccolor")
            {
                Console.Write("Enter:");
                int c = int.Parse(Console.ReadLine());
                
                File.WriteAllText("colorcache.txt", c.ToString());
                
                obj.ccolor(c);
                Console.WriteLine("COLOR SUCCESFULLY CHANGED!!");

            }
            else if (prompt == "pass")
            {
                Console.WriteLine("Enter old password:");
                
                Console.ForegroundColor = ConsoleColor.Black;
                string o = Console.ReadLine();
                string e = File.ReadAllText("SAM.txt");
                if (o == e)
                {
                    string p = Console.ReadLine();
                    File.WriteAllText("SAM.txt", p.ToString());
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("PASSWORD CHANGED! Shark Prompt should now exit");

                }
                
                
                prompt = "exit";
            }
            else if (prompt == "display")
            {
                Console.Write("Enter:");
                string echoinput = Console.ReadLine();
                obj.echo(echoinput);
            }
            else if (prompt == "dir")
            {
                Console.Write("Enter:");
                string target = Console.ReadLine();
                obj.dir(target);
            }
            else if (prompt == "cls")
            {
                obj.cls();
            }
            else if (prompt == "create")
            {
                Console.Write("Enter target:");
                string t = Console.ReadLine();
                obj.create(t);
                Console.WriteLine("For Better Results SHARK should restart");
                Console.ReadLine();
                prompt = "exit";
                
            }
            else if (prompt == "open")
            {
                Console.Write("Enter target:");
                string t = Console.ReadLine();
                obj.open(t);
            }
            else if (prompt == "edit")
            {
                Console.Write("Enter target:");
                string t = Console.ReadLine();
                obj.edit(t);
            }
            else if (prompt == "delete")
            {
                Console.Write("Enter target:");
                string t = Console.ReadLine();
                obj.delete(t);
            }
            else if (prompt == "cut")
            {
                Console.Write("Enter target of file:");
                string t = Console.ReadLine();
                Console.Write("Enter destination:");
                string d = Console.ReadLine();
                obj.cut(t, d);
            }
            else if (prompt == "copy")
            {
                Console.Write("Enter target fof file:");
                string t = Console.ReadLine();
                Console.Write("Enter destination:");
                string d = Console.ReadLine();
                obj.copy(t, d);
            }       
            else if (prompt == "exit")
            {
                Console.WriteLine("Exiting......... Press ENTER to continue");
            }
            else
            {
                Console.WriteLine("Unrecognized Command");
           
            }
            
           if (prompt == "exit")
            {
                
            }
            else
            {
                Console.ReadLine();
                Main();
            }
            
            Console.ReadLine();
            

        }





        public void cls()
        {
            Console.Clear();
        }
        public void cut(string target, string dest)
        {
            File.Move(target, dest);
        }
        public void copy(string target, string dest)
        {
            File.Copy(target, dest);
        }

        public void dir(string target)
        {
            DirectoryInfo inf = new DirectoryInfo(@target);
            FileInfo [] filinf = inf.GetFiles();
            string[] dirs = Directory.GetDirectories(@target, "*");
            foreach (FileInfo file in filinf)
            {
                Console.WriteLine("File Name:" + file.Name + "\tsize:" + file.Length);
            }
            foreach (string dir in dirs)
            {
                Console.WriteLine("Directory Name:" + dir);
            }

        }




        public void create(string target)
        {
            Program ob = new Program();
            if (File.Exists(target))
            {

                Console.WriteLine("This File Already exists. Do you want to open it?");
                char op = char.Parse(Console.ReadLine());
                if (op == 'y')
                {
                    ob.open(target);
                }
                else
                {
                    Console.WriteLine(" Then do you want to Override it?");
                    op = char.Parse(Console.ReadLine());
                    if (op == 'y')
                    {
                        ob.delete(target);
                        ob.create(target);
                    }
                    else
                    {
                        Console.WriteLine("Delete it?");
                        op = char.Parse(Console.ReadLine());
                        if (op == 'y')
                        {
                            ob.delete(target);
                        }
                        else
                        {
                            Main();
                        }
                    }

                }
            }
            else
            {
                File.Create(target);
                Console.WriteLine("File Created SUCCESSFULLY");
                Console.ReadLine();
                
            }
        }

        public void delete(string target)
        {
            Console.WriteLine("Are you sure you want to delete it?");
            char ch = char.Parse(Console.ReadLine());
            if (ch == 'y')
            {
                File.Delete(target);
                Console.WriteLine("File DELETED SUCCESSFULLY");
            }
            else
            {
                Console.WriteLine("File DELETE ERROR");
            }
        }
        public void open(string target)
        {
            Console.WriteLine("File OPENED SUCCESSFULLY:");
            
            string file = File.ReadAllText(target);
            Console.WriteLine(file);
            Console.ReadLine();
        }


        public void edit(string target)
        {
            string fil = File.ReadAllText(target);
            Console.WriteLine(fil);
            StreamWriter myosw = new StreamWriter(target, true);
            string writer = Console.ReadLine();
            myosw.WriteLine(writer);
            myosw.Close();
            Console.WriteLine("File Edited SUCCESSFULLY:");

        }
        
        public void shutdown()
        {
        
        }
        public void restart()
        {
         
        }

        
        
        
        
        
        
        public void echo(string inp)
        {
            Console.WriteLine(inp);
        }
           
        
        
        
        
        
        
        
        
        public void ccolor(int cchoice)
            {
             
            switch (cchoice)
                {
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Black;
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        break;
                    case 4:
                        Console.ForegroundColor = ConsoleColor.DarkBlue;
                        break;
                    case 5:
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                        break;
                    case 6:
                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        break;
                    case 7:
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        break;
                    case 8:
                        Console.ForegroundColor = ConsoleColor.DarkMagenta;
                        break;
                    case 9:
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        break;
                    case 10:
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        break;
                    case 11:
                        Console.ForegroundColor = ConsoleColor.Gray;
                        break;
                    case 12:
                        Console.ForegroundColor = ConsoleColor.Green;
                        break;
                    case 13:
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        break;
                    case 14:
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;
                    case 15:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        break;
                    default:
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;
                        
            }


                Console.ReadLine();
        }      
    }
}
    

